package com.xx.rpc.core.remoting.invoker.router.impl;

import com.xx.rpc.core.remoting.invoker.router.XxRpcLoadBalance;

import java.util.Random;
import java.util.TreeSet;

/**
 * random 随机策略
 *
 * @author hanxiyue
 */
public class XxRpcLoadBalanceRandomStrategy extends XxRpcLoadBalance {
    private Random random = new Random();

    @Override
    public String route(String serviceKey, TreeSet<String> addressSet) {
        // arr
        String[] addressArr = addressSet.toArray(new String[addressSet.size()]);

        // random
        String finalAddress = addressArr[random.nextInt(addressSet.size())];
        return finalAddress;
    }
}
